package interfacedemo1;

public class DataInterImpl2 implements DataInter {
    private Students[] students;
    public DataInterImpl2(Students[] students)
    {
        this.students = students;
    }

    @Override//重写打印所有学生成绩+男女学生个数
    public void printAllScore() {
        int MaleNum = 0;//记录男生人数
        for (int i = 0; i < students.length; i++) {
            Students s = students[i];
            if(s.getSex()=='男')
            {
                MaleNum++;

            }
            System.out.println(s.getName()+" "+s.getSex()+" "+s.getScore());
        }
        System.out.println("男学生个数："+MaleNum);
        System.out.println("女学生个数："+(students.length-MaleNum));

    }

    @Override//重写打印平均分+最大分+最小分
    public void printAvgScore() {
        Students s1 = students[0];
        double sum =s1.getScore();//赋第一个学生成绩给sum
        double max =s1.getScore();//赋第一个学生成绩给max
        double min =s1.getScore();//赋第一个学生成绩给min

        for (int i = 1; i < students.length; i++) {//重第二个学生开始遍历
            Students s = students[i];
            sum += s.getScore();

            if(s.getScore() > max)
            {
                max = s.getScore();
            }

            if(s.getScore() < min)
            {
                min = s.getScore();
            }
        }

        System.out.println("最高分："+max);
        System.out.println("最低分："+min);
        System.out.println("总分是：" + sum);

        System.out.println("平均分是：" +(sum-max-min)/(students.length - 2));

    }
}
